package com.yy.kit.http;

import java.io.UnsupportedEncodingException;
import java.util.Map;
import java.util.Set;

import javax.servlet.http.HttpServletRequest;

import com.yy.kit.collections.YYMapKits;

/**
 * <p>
 * 操作request的工具类
 * </p>
 * 
 * @author 杨阳
 * @since 2017年9月28日
 */
public class YYRequestKits {

	/**
	 * <p>
	 * 获取rquest的参数，将参数全部放到map中
	 * </p>
	 * 
	 * @param request
	 *            {@link HttpServletRequest}
	 * @return {@link Map}<String, String>
	 * @author 杨阳
	 * @throws UnsupportedEncodingException 
	 * @since 2017年9月28日
	 */
	public static Map<String, String> getRequestParams(HttpServletRequest request) throws UnsupportedEncodingException {
		request.setCharacterEncoding("UTF-8");
		Map<String, String> params = YYMapKits.createStringHashMap();
		if (null != request) {
			Set<String> paramsKey = request.getParameterMap().keySet();
			for (String key : paramsKey) {
				params.put(key, request.getParameter(key));
			}
		}
		return params;
	}
}
